<template>
  <textarea id="editor" style="width:100%;height:300px;"></textarea>
</template>
<script>

import '../../../static/umeditor/themes/default/css/umeditor.min.css';
import '../../../static/umeditor/umeditor.config.js';
import '../../../static/umeditor/umeditor.min.js';
import '../../../static/umeditor/lang/zh-cn/zh-cn.js';

	export default{
		data(){
			return{
        um:{},
			}
		},
    methods:{
      initEditor(){
         this.um = UM.getEditor('editor', {
          //lang:/^zh/.test(navigator.language || navigator.browserLanguage || navigator.userLanguage) ? 'zh-cn' : 'en',
          focus: true,
          autoHeightEnabled: true,
          autoFloatEnabled: true,
          height:360,
          BaseUrl: '',
          UEDITOR_HOME_URL: '/static/umeditor/',
          imageUrl:'/dash/upload/upload_umeditor_file',
          imageFieldName:'upload',"imageMaxSize": 2048,
          imageAllowFiles: [".png", ".jpg", ".jpeg", ".gif"],
          imagePathFormat:'',
          imagePath:''
          //focus: true

        });
      },
      getUMContent(){
       return this.um.getContent();
      },

      setUMContent(content){
         /**
          * 第二个参数千万不能为true
          * 为true，会添加一个空行，巨坑无比！
          */
        this.um.setContent(content,false);
      }
    },
		created(){
      console.log('sub created')
		},
		mounted(){

      this.initEditor();

      this.um.addListener( 'ready', function( editor ) {
          /**
          * 第二个参数千万不能为true
          * 为true，会添加一个空行，巨坑无比！
          */
          //this.um.setContent(content, true);
          //this.um.setContent(content,false);
      });

    },
    updated(){
    },
    destroyed() {
      this.um.destroy();
    },
	}
</script>
